//
//  MainViewController.m
//  gpos_app
//
//  Created by apple on 2018/8/13.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "MainViewController.h"
#import "XMHomeViewController.h"
#import "XMPageViewController.h"
#import "XMThreeViewController.h"
#import "XMFourViewController.h"
#import "XMFiveViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController


//改变状态栏
-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadSubviewcontrollers];
    
}

- (void)loadSubviewcontrollers{
    
    XMHomeViewController * HomeVC = [[XMHomeViewController alloc] init];
    
    XMPageViewController * PageVC = [[XMPageViewController alloc] init];
    
    XMThreeViewController * ThreeVC = [[XMThreeViewController alloc] init];
    
    XMFourViewController * FourVC = [[XMFourViewController alloc] init];
    
    XMFiveViewController * FiveVC = [[XMFiveViewController alloc] init];
//NSMutableArray
    NSArray * Arr = @[HomeVC,PageVC,ThreeVC,FourVC,FiveVC];
    NSMutableArray * mar = [NSMutableArray array];
    NSArray * titleArr = @[@"首页",@"竞选",@"财富",@"商家",@"我的"];
    
    //图片名字数组
    NSArray * imagesStr = @[@"icon_sy_h", @"icon_jx_h",@"icon_cf_h", @"icon_sc_h", @"icon_wd_h"];
    
    //选中图片名字数组
    NSArray * selectedImages = @[@"icon_shouye_l", @"icon_jx_l",@"icon_caiful", @"icon_sc_l", @"icon_wd_l"];
    
    NSUInteger count = Arr.count;
    for (int i = 0; i < count; i++){
        
        UIViewController * vc = Arr[i];
        UINavigationController * navig = [[UINavigationController alloc] initWithRootViewController:vc];
    
        [self setTitle:titleArr[i] andImage:imagesStr[i] andSelectedImage:selectedImages[i] andController:vc];

        [mar addObject:navig];
    
    }
    
    self.viewControllers = mar;
}
- (void)setTitle:(NSString *)title andImage:(NSString *)image andSelectedImage:(NSString *)selectedImage andController:(UIViewController *)controller{
    
    //设置标题
    controller.title = title;
    
    //当普通状态下的 字体的大小和颜色
    NSDictionary * arrtibutesDict = @{NSFontAttributeName : [UIFont systemFontOfSize:10.f],
                                      NSForegroundColorAttributeName : [UIColor grayColor]};
    
    
    //这个是设置标签栏上每个子标签的 标题的，可以设置它的标题的文本样式（字体大小，字体颜色。。。）
    [controller.tabBarItem setTitleTextAttributes:arrtibutesDict forState:UIControlStateNormal];
    
    
    //当这个item在被选中状态下的 字体和图片
    NSDictionary * selectedArrtibutesDict = @{NSFontAttributeName : [UIFont systemFontOfSize:11.f],
                                              NSForegroundColorAttributeName : [UIColor blueColor]};
    
    [controller.tabBarItem setTitleTextAttributes:selectedArrtibutesDict forState:UIControlStateSelected];
    
    
    //设置图片
    [controller.tabBarItem setImage:[UIImage imageNamed:image]];
    
    //设置选中图
    UIImage * selected = [UIImage imageNamed:selectedImage];
    
    //设置这个图片的渲染模式， 是选择渲染原图，还是按照系统样式改
    /**
     *  参数是 一个枚举类型， 不同类型值，对应不同的图片渲染类型
     *   返回值是 UIImage， 一张新的图片对象。
     */
    UIImage * renderImage = [selected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    [controller.tabBarItem setSelectedImage: renderImage];
    
    
}

-(UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
